﻿/// Write a program to check if in a given expression the brackets are put correctly.
/// Example of correct expression: ((a+b)/5-d).
/// Example of incorrect expression: )(a+b)).


using System;

class zad3
{
    static void Main()
    {
        string sampleImput = "((a + b) / 5 - d)";
        //string sampleImput = ")(a+b))";

        if (CheckExpretion(sampleImput))
        {
            Console.WriteLine("the expretion {0} is correct", sampleImput);
        }
        else
        {
            Console.WriteLine("the expretion {0} is NOT correct", sampleImput);
        }
    }

    public static bool CheckExpretion(string s)
    {
        int openBrackets = 0;
        int closedBrackets = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == '(')
            {
                openBrackets++;
            }
            else if (s[i] == ')')
            {
                closedBrackets++;
            }
        }

        if (closedBrackets == openBrackets)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

